<template>
  <!-- 放置一个图标 -->
  <div>
    <svg-icon
      v-if="flag"
      icon-class="fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
    <svg-icon
      v-else
      icon-class="exit-fullscreen"
      class="fullscreen"
      @click="toggleFullScreen"
    />
  </div>
</template>

<script>
import ScreenFull from 'screenfull'
export default {
  name: 'ScreenFull',
  data() {
    return {
      flag: true
    }
  },
  methods: {
    toggleFullScreen() {
      if (ScreenFull.isEnabled) {
        ScreenFull.toggle() // 一行代码实现切换
        this.flag = !this.flag
      } else {
        this.$message.error('兄弟, 您的浏览器版本过低, 不支持全屏功能哦!')
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.fullscreen {
  width: 20px;
  height: 20px;
  color: #fff;
  cursor: pointer;
}
</style>
